﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataEditor.Views;
using System.ComponentModel.Composition;
using Caliburn.Micro;

namespace DataEditor.ViewModels
{
    [Export(typeof(IShell))]
    public class MainWindowViewModel : BaseViewModel, IShell
    {
        readonly IWindowManager _windowManager;
        readonly IEventAggregator _eventAggregator;

        #region Constructors

        [ImportingConstructor()]
        public MainWindowViewModel(IEventAggregator eventAggregator, IWindowManager windowManager)
        {
            _windowManager = windowManager;
            _eventAggregator = eventAggregator;
            MakeCommands();
        }

        #endregion

        #region Properties

        RelayCommand _unitsOpenCommand;
        public RelayCommand UnitsOpenCommand
        {
            get
            {
                return _unitsOpenCommand;
            }
            set
            {
                _unitsOpenCommand = value;
                NotifyOfPropertyChange(() => UnitsOpenCommand);

            }
        }

        RelayCommand _symbolsOpenCommand;
        public RelayCommand SymbolsOpenCommand
        {
            get
            {
                return _symbolsOpenCommand;
            }
            set
            {
                _symbolsOpenCommand = value;
                NotifyOfPropertyChange(() => SymbolsOpenCommand);

            }
        }

        private RelayCommand _indicatorTypesOpenCommand;
        public RelayCommand IndicatorTypesOpenCommand
        {
            get { return _indicatorTypesOpenCommand; }
            set { _indicatorTypesOpenCommand = value; }
        }

        private RelayCommand _indicatorsOpenCommand;
        public RelayCommand IndicatorsOpenCommand
        {
            get { return _indicatorsOpenCommand; }
            set { _indicatorsOpenCommand = value; }
        }

        private RelayCommand _prefixesOpenCommand;
        public RelayCommand PrefixesOpenCommand
        {
            get { return _prefixesOpenCommand; }
            set { _prefixesOpenCommand = value; }
        }
        #endregion

        #region Actions/methods

        private void MakeCommands()
        {
            _unitsOpenCommand = new RelayCommand(
                param =>
                {
                    var unitsViewModel = new UnitsViewModel();
                    Nullable<Boolean> result = _windowManager.ShowDialog(unitsViewModel);
                    if (result.HasValue && result.Value == true)
                    {
                    }

                },
                (param) =>
                {
                    return true;
                }
                );

            _symbolsOpenCommand = new RelayCommand(
                param =>
                {
                    var symbolsViewModel = new SymbolsViewModel();
                    Nullable<Boolean> result = _windowManager.ShowDialog(symbolsViewModel);
                    if (result.HasValue && result.Value == true)
                    {
                    }

                },
                (param) =>
                {
                    return true;
                }
                );

            _indicatorTypesOpenCommand = new RelayCommand(
                param =>
                {
                    var indTpesVM = new IndicatorTypesViewModel();
                    Nullable<Boolean> result = _windowManager.ShowDialog(indTpesVM);

                },
                (param) =>
                {
                    return true;
                }
                );

            _prefixesOpenCommand = new RelayCommand(
                (exe) =>
                {
                    var prefixViewModel = new PrefixViewModel();
                    Nullable<Boolean> result = _windowManager.ShowDialog(prefixViewModel);
                },
                    (canExe) =>
                    {
                        return true;
                    }
);
            _indicatorsOpenCommand = new RelayCommand(
                        param =>
                        {
                            var indicatorsViewModel = new IndicatorsViewModel(_eventAggregator, _windowManager);
                            Nullable<Boolean> result = _windowManager.ShowDialog(indicatorsViewModel);
                        }
                        );
        }
        #endregion


    }
}
